

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/zoro.jpg">
  <link rel="icon" href="/img/zoro.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#efb9b9">
  <meta name="description" content="">
  <meta name="author" content="AgoniLay">
  <meta name="keywords" content="">
  
  <title>NodeJS笔记 - AgoniLay的博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.7.2/styles/arta.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->

  
<link rel="stylesheet" href="/css/scroller.css">
<link rel="stylesheet" href="/css/bynode.css">
<link rel="stylesheet" href="/css/mouse.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"agonilay.github.io","root":"/","version":"1.8.11","typing":{"enable":true,"typeSpeed":150,"cursorChar":"❤","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading2.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>AgoniLay</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-bookmark"></i>
                索引
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="/archives/">
                    <i class="iconfont icon-archive-fill"></i>
                    归档
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/categories/">
                    <i class="iconfont icon-category-fill"></i>
                    分类
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/tags/">
                    <i class="iconfont icon-tags-fill"></i>
                    标签
                  </a>
                
              </div>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/zoro2.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h3" id="subtitle" title="NodeJS笔记">
              
            </span>

            
              <div class="mt-3">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-author" aria-hidden="true"></i>
      AgoniLay
    </span>
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-07-29 23:23" pubdate>
        2021年7月29日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      58
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
			
			
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">NodeJS笔记</h1>
            
            <div class="markdown-body">
              <h3 id="一、NodeJS-简介"><a href="#一、NodeJS-简介" class="headerlink" title="一、NodeJS 简介"></a>一、NodeJS 简介</h3><h4 id="1-1-Node-js-是什么"><a href="#1-1-Node-js-是什么" class="headerlink" title="1.1 Node.js 是什么"></a>1.1 Node.js 是什么</h4><p>Node.js 是 JavaScript 运行环境</p>
<p>可以直接通过浏览器访问 JavaScript 代码</p>
<h4 id="1-2-能干什么"><a href="#1-2-能干什么" class="headerlink" title="1.2 能干什么"></a>1.2 能干什么</h4><p>作用：让 JavaScript 成为与 PHP、Python 等平起平坐的语言</p>
<p>概括：前端脱离后端，直接通过 JS 写项目</p>
<h4 id="1-3-下载"><a href="#1-3-下载" class="headerlink" title="1.3 下载"></a>1.3 下载</h4><p>官网：<a target="_blank" rel="noopener" href="http://nodejs.org/">http://nodejs.org</a></p>
<p>中文网址：<a target="_blank" rel="noopener" href="http://nodejs.cn/">http://nodejs.cn</a></p>
<p>学习社区：condjs.org</p>
<ul>
<li>nvm 工具：实现 nodejs 任意版本的切换</li>
<li>npm 工具：下载 nodejs 所需模块（工具库）</li>
<li>nrm 工具：切换 npm 下载源</li>
</ul>
<h3 id="二、安装-NodeJS"><a href="#二、安装-NodeJS" class="headerlink" title="二、安装 NodeJS"></a>二、安装 NodeJS</h3><h3 id="三、初体验-REPL-（了解）"><a href="#三、初体验-REPL-（了解）" class="headerlink" title="三、初体验 REPL （了解）"></a>三、初体验 REPL （了解）</h3><ul>
<li>R  read  读取（读取用户输入的 JS 代码）</li>
<li>E  exec  执行（执行用户输入的 JS 代码）</li>
<li>P  print  打印（打印用户输入的 JS 代码）</li>
<li>L  loop  循环（后续所有的 JS 代码执行都会循环以上命令）</li>
<li><div class="hljs code-wrapper"><pre><code>          退出（按两下 ctrl + c）
</code></pre></div>
</li>
</ul>
<h4 id="仿谷歌控制台"><a href="#仿谷歌控制台" class="headerlink" title="仿谷歌控制台"></a>仿谷歌控制台</h4><p>cmd窗口输入 node 回车开启仿谷歌控制台</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">cls <span class="hljs-comment">// 清屏</span><br></code></pre></div></td></tr></table></figure>

<h4 id="初体验"><a href="#初体验" class="headerlink" title="初体验"></a>初体验</h4><p>cmd窗口中 cd 到该目录下输入：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">node hello.js<br></code></pre></div></td></tr></table></figure>

<h3 id="四、模块系统"><a href="#四、模块系统" class="headerlink" title="四、模块系统"></a>四、模块系统</h3><h4 id="4-1-简介"><a href="#4-1-简介" class="headerlink" title="4.1 简介"></a>4.1 简介</h4><h5 id="使用-NodeJS-编写应用程序主要使用："><a href="#使用-NodeJS-编写应用程序主要使用：" class="headerlink" title="使用 NodeJS 编写应用程序主要使用："></a>使用 NodeJS 编写应用程序主要使用：</h5><ul>
<li>ECMAScript语法：变量、判断、循环等语法（JS三大组成部分：ECMA/DOM/BOM）</li>
<li>内置/核心模块：http 服务、fs 文件操作、url 路径、 path 路径处理、os 操作系统</li>
<li>第三方模块：</li>
<li>自定义模块：自己创建的 js 文件</li>
</ul>
<h5 id="CommonJS-模块规范"><a href="#CommonJS-模块规范" class="headerlink" title="CommonJS 模块规范"></a>CommonJS 模块规范</h5><ul>
<li>一个文件就是一个模块</li>
<li>通过 exports 和 module.exports 来导出模块中的成员（声明模块中那些功能可以使用）</li>
<li>通过 require 来加载模块</li>
</ul>
<h4 id="4-2-自定义-Node-js-模块"><a href="#4-2-自定义-Node-js-模块" class="headerlink" title="4.2 自定义 Node.js 模块"></a>4.2 自定义 Node.js 模块</h4><h5 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h5><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 步骤1：导出成员（声明模块/文件中那些方法可以被外部使用）</span><br><span class="hljs-comment">// 写法1</span><br><span class="hljs-built_in">exports</span>.属性/方法名 = 功能<br><span class="hljs-comment">// 写法2</span><br><span class="hljs-built_in">module</span>.exports.属性/方法名 = 变量名<br><br><span class="hljs-comment">// 步骤2：导出成员（声明模块/文件中那些方法可以被外部使用）</span><br><span class="hljs-keyword">var</span> 对象 = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;路径及文件名&#x27;</span>);<br>对象.属性或方法名;<br></code></pre></div></td></tr></table></figure>

<h6 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h6><p>b.js</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 步骤1：定义</span><br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"></span>) </span>&#123;<br>  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;this is add&#x27;</span>);<br>&#125;<br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">del</span>(<span class="hljs-params"></span>) </span>&#123;<br>  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;this is del&#x27;</span>);<br>&#125;<br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">edit</span>(<span class="hljs-params"></span>) </span>&#123;<br>  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;this is edit&#x27;</span>);<br>&#125;<br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">select</span>(<span class="hljs-params"></span>) </span>&#123;<br>  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;this is select&#x27;</span>);<br>&#125;<br><span class="hljs-comment">// 步骤二：导出（语法：exports/module.exports.成员名 = 值）</span><br><span class="hljs-built_in">exports</span>.add = add;<br><span class="hljs-built_in">exports</span>.del = del;<br><span class="hljs-built_in">exports</span>.edit = edit;<br><span class="hljs-built_in">exports</span>.select = select;<br></code></pre></div></td></tr></table></figure>

<p>a.js</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 引入自定义模块</span><br><span class="hljs-keyword">var</span> b = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;./b&#x27;</span>); <span class="hljs-comment">// 注：.js不用写</span><br><br><span class="hljs-built_in">console</span>.log(b);<br><br>b.add();<br>b.del();<br></code></pre></div></td></tr></table></figure>

<p>exports 就是 module.exports 的简写</p>
<h4 id="4-3-第三方-Node-js-模块"><a href="#4-3-第三方-Node-js-模块" class="headerlink" title="4.3 第三方 Node.js 模块"></a>4.3 第三方 Node.js 模块</h4><h4 id="4-4-内置-Node-js-模块"><a href="#4-4-内置-Node-js-模块" class="headerlink" title="4.4 内置 Node.js 模块"></a>4.4 内置 Node.js 模块</h4><h5 id="os-模块：操作系统-（了解）"><a href="#os-模块：操作系统-（了解）" class="headerlink" title="os 模块：操作系统 （了解）"></a>os 模块：操作系统 （了解）</h5><p>提供了一些操作系统相关的实用方法</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 引入</span><br><span class="hljs-keyword">const</span> os = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;os&#x27;</span>);<br></code></pre></div></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 1. 创建os对象（引入ondejs内置os对象）</span><br><span class="hljs-keyword">var</span> os = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;os&#x27;</span>);<br><span class="hljs-comment">// 2. 调用os对象方法获取系统数据</span><br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;hello，&#x27;</span>        + os.EOL         + <span class="hljs-string">&#x27;itcast&#x27;</span>); <br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;主机名：&#x27;</span>        + os.hostname()); <br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;操作系统名：&#x27;</span>     + os.type()); <br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;操作系统平台：&#x27;</span>	+ os.platform()); <br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;内存总量：&#x27;</span>       + os.totalmem()   + <span class="hljs-string">&#x27; 字节.&#x27;</span>); <br><span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;空闲内存：&#x27;</span>       + os.freemem()    + <span class="hljs-string">&#x27; 字节.&#x27;</span>); <br></code></pre></div></td></tr></table></figure>

<h6 id="字节概念："><a href="#字节概念：" class="headerlink" title="字节概念："></a>字节概念：</h6><p>1字节（Byte）= 8位（bit）</p>
<p>1KB = 1024Byte（字节）</p>
<p>1M = 1024KB</p>
<p>1G = 1024M</p>
<h5 id="path-模块：路径处理"><a href="#path-模块：路径处理" class="headerlink" title="path 模块：路径处理"></a>path 模块：路径处理</h5><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// dirname	后去一层</span><br><span class="hljs-comment">// basename 取最后一层</span><br><br><span class="hljs-comment">// 1. 引入内置模块</span><br><span class="hljs-keyword">var</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;path&#x27;</span>)<br><span class="hljs-comment">// 2. 练习</span><br><span class="hljs-keyword">var</span> testData = <span class="hljs-string">&#x27;c:/Users/AgoniLay/Desktop/zbw/work/index.html&#x27;</span>;<br><br><span class="hljs-built_in">console</span>.log(path.basename(testData)); <span class="hljs-comment">// index.html</span><br>testData = path.dirname(testData)<br><span class="hljs-built_in">console</span>.log(testData); <span class="hljs-comment">// c:/Users/AgoniLay/Desktop/zbw/work</span><br><span class="hljs-built_in">console</span>.log(path.basename(testData)); <span class="hljs-comment">// work</span><br></code></pre></div></td></tr></table></figure>

<h5 id="url-模块：网址处理"><a href="#url-模块：网址处理" class="headerlink" title="url 模块：网址处理"></a>url 模块：网址处理</h5><p>需求：获取网址 <a target="_blank" rel="noopener" href="http://itcast.cn/?name=AgoniLay&amp;age=19">http://itcast.cn?name=AgoniLay&amp;age=19</a> 中的参数</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 1. 引入url内置模块</span><br><span class="hljs-keyword">var</span> url = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;url&#x27;</span>)<br><span class="hljs-comment">// 2. 使用</span><br><span class="hljs-keyword">var</span> data = <span class="hljs-string">&#x27;http://itcast.cn?name=AgoniLay&amp;age=19&#x27;</span>;<br><br><span class="hljs-built_in">console</span>.log(data);<br><span class="hljs-built_in">console</span>.log(url.parse(data));<br><span class="hljs-built_in">console</span>.log(url.parse(data, <span class="hljs-literal">true</span>)); <span class="hljs-comment">// query值转换为对象</span><br><br><span class="hljs-keyword">var</span> urlQueryObj = url.parse(data, <span class="hljs-literal">true</span>)<br><span class="hljs-built_in">console</span>.log(urlQueryObj.query); <span class="hljs-comment">// &#123; name: &#x27;AgoniLay&#x27;, age: &#x27;19&#x27; &#125;</span><br><span class="hljs-built_in">console</span>.log(urlQueryObj.query.name); <span class="hljs-comment">// AgoniLay</span><br><span class="hljs-built_in">console</span>.log(urlQueryObj.query.age); <span class="hljs-comment">// 19</span><br></code></pre></div></td></tr></table></figure>

<h5 id="fs-模块：文件系统"><a href="#fs-模块：文件系统" class="headerlink" title="fs 模块：文件系统"></a>fs 模块：文件系统</h5><h6 id="1-写入文件"><a href="#1-写入文件" class="headerlink" title="1. 写入文件"></a>1. 写入文件</h6><p>语法</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 1. 引入 fs 内置对象</span><br><span class="hljs-keyword">var</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;fs&#x27;</span>)<br><br><span class="hljs-comment">// 2. 调用函数写数据进文件</span><br>fs.writeFile(<span class="hljs-string">&#x27;路径及文件名&#x27;</span>, <span class="hljs-string">&#x27;数据&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>&#123;<br>    <span class="hljs-comment">// err   为 null -则写入成功</span><br>    <span class="hljs-comment">// err 不为 null -则写入失败</span><br>&#125;);<br></code></pre></div></td></tr></table></figure>

<p>练习：通过 write.js 创建 a.txt 写入 你好，AgoniLay</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js">fs.writeFile(<span class="hljs-string">&#x27;./a.txt&#x27;</span>, <span class="hljs-string">&#x27;你好，AgoniLay&#x27;</span>, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> &#123;<br>    <span class="hljs-comment">// err 为null     成功</span><br>    <span class="hljs-comment">// err 不为null   有瑕疵</span><br>    <span class="hljs-keyword">if</span> (err) &#123;<br>        <span class="hljs-built_in">console</span>.log(err);<br>        <span class="hljs-keyword">return</span>;<br>    &#125;<br>    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;success&#x27;</span>);<br>&#125;);<br></code></pre></div></td></tr></table></figure>

<h6 id="2-读取文件"><a href="#2-读取文件" class="headerlink" title="2. 读取文件"></a>2. 读取文件</h6><p>语法</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 调用函数从文件读数据</span><br>fs.writeFile(<span class="hljs-string">&#x27;路径及文件名&#x27;</span>, <span class="hljs-string">&#x27;数据&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>&#123;<br>    <span class="hljs-comment">// err   为 null -则读取成功</span><br>    <span class="hljs-comment">// err  不为 null -则读取失败</span><br>&#125;);<br></code></pre></div></td></tr></table></figure>

<p>练习：通过 read.js 文件读取 a.txt 内容</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js">fs.readFile(<span class="hljs-string">&#x27;./a.txt&#x27;</span>, <span class="hljs-function">(<span class="hljs-params">err, data</span>) =&gt;</span> &#123;<br>    <span class="hljs-comment">// err 为null     成功</span><br>    <span class="hljs-comment">// err 不为null   有瑕疵</span><br>    <span class="hljs-keyword">if</span> (err) &#123;<br>        <span class="hljs-built_in">console</span>.log(err);<br>        <span class="hljs-keyword">return</span>;<br>    &#125;<br>    <span class="hljs-built_in">console</span>.log(data);  <span class="hljs-comment">// 默认不是我们可识别的内容</span><br>    					<span class="hljs-comment">// 而是 Buffer对象</span><br>    <span class="hljs-comment">// 通过 Buffer对象.toString() 转化为字符显示</span><br>    <span class="hljs-built_in">console</span>.log(data.toString());<br>&#125;);<br></code></pre></div></td></tr></table></figure>

<p>省去转换，提前声明：</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 多学一招：前期读的时候就声明</span><br>fs.readFile(<span class="hljs-string">&#x27;./a.txt&#x27;</span>, <span class="hljs-string">&#x27;utf8&#x27;</span>, <span class="hljs-function">(<span class="hljs-params">err, data</span>) =&gt;</span> &#123;<br>    <span class="hljs-comment">// err 为null     成功</span><br>    <span class="hljs-comment">// err 不为null   有瑕疵</span><br>    <span class="hljs-keyword">if</span> (err) &#123;<br>        <span class="hljs-built_in">console</span>.log(err);<br>        <span class="hljs-keyword">return</span>;<br>    &#125;<br>    <span class="hljs-built_in">console</span>.log(data);<br>&#125;);<br></code></pre></div></td></tr></table></figure>

<h5 id="http-模块（构建-http-服务器）"><a href="#http-模块（构建-http-服务器）" class="headerlink" title="http 模块（构建 http 服务器）"></a>http 模块（构建 http 服务器）</h5><h6 id="1-创建-http-服务器"><a href="#1-创建-http-服务器" class="headerlink" title="1. 创建 http 服务器"></a>1. 创建 http 服务器</h6><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">//  1. 引入 http 模块</span><br><span class="hljs-keyword">var</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;http&#x27;</span>)<br><br><span class="hljs-comment">// 2. 创建web服务器</span><br><span class="hljs-keyword">var</span> server = http.createServer();<br><span class="hljs-comment">// 3. 监听请求</span><br>server.on(<span class="hljs-string">&#x27;request&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req, res</span>) </span>&#123; <span class="hljs-comment">// req - request 请求  res - response 响应</span><br>    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;收到客户端请求，请求地址：&#x27;</span> + req.url);<br>    <br>    <span class="hljs-comment">// 响应数据</span><br>    res.write(<span class="hljs-string">&#x27;hello AgoniLay&#x27;</span>);<br>	res.end();<br>&#125;)<br><span class="hljs-comment">// 4. 启动服务</span><br>server.listen(<span class="hljs-number">8080</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>&#123;<br>    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;服务启动成功，访问：http://localhost:8080&#x27;</span>);<br>&#125;)<br></code></pre></div></td></tr></table></figure>

<h6 id="2-响应不同数据"><a href="#2-响应不同数据" class="headerlink" title="2. 响应不同数据"></a>2. 响应不同数据</h6><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 解决乱码</span><br>res.setHeader(<span class="hljs-string">&#x27;Content-Type&#x27;</span>, <span class="hljs-string">&#x27;text/html;charset=utf-8&#x27;</span>)<br></code></pre></div></td></tr></table></figure>

<p>判断用户访问的是首页还是登录页</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 判断请求的地址</span><br><span class="hljs-keyword">if</span> (req.url == <span class="hljs-string">&#x27;/&#x27;</span> || req.url == <span class="hljs-string">&#x27;/index&#x27;</span>) &#123;<br>    $msg = <span class="hljs-string">&#x27;this is index&#x27;</span><br>&#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (req.url == <span class="hljs-string">&#x27;/login&#x27;</span>) &#123;<br>    $msg = <span class="hljs-string">&#x27;this is login&#x27;</span><br>&#125; <span class="hljs-keyword">else</span> &#123;<br>    $msg = <span class="hljs-string">&#x27;404&#x27;</span><br>&#125;<br></code></pre></div></td></tr></table></figure>

<h3 id="五、请求和响应对象"><a href="#五、请求和响应对象" class="headerlink" title="五、请求和响应对象"></a>五、请求和响应对象</h3><h4 id="语法-1"><a href="#语法-1" class="headerlink" title="语法"></a>语法</h4><h5 id="请求对象（request）"><a href="#请求对象（request）" class="headerlink" title="请求对象（request）"></a>请求对象（request）</h5><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js">req.headers			获取请求头信息（对象）<br>req.rawHeaders		获取请求头信息（数组）<br>req.httpVersion		获取 HTTP 版本<br>req.method			获取请求方法<br>req.url				获取请求路径（注：不含网址）<br></code></pre></div></td></tr></table></figure>

<h5 id="响应对象（response）"><a href="#响应对象（response）" class="headerlink" title="响应对象（response）"></a>响应对象（response）</h5><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js">res.statusCode = <span class="hljs-number">404</span>;<br>res.statusMessage = <span class="hljs-string">&#x27;Not Found&#x27;</span>;<br>res.setHeader(<span class="hljs-string">&#x27;Content-Type&#x27;</span>, <span class="hljs-string">&#x27;text/html;charset=utf-8&#x27;</span>);<br><br><span class="hljs-comment">// 简化版</span><br>res.writeHeader(<span class="hljs-string">&#x27;404&#x27;</span>, <span class="hljs-string">&#x27;Not Found&#x27;</span>, &#123;<br>    <span class="hljs-string">&#x27;Content-Type&#x27;</span>: <span class="hljs-string">&#x27;text/html;charset=utf-8&#x27;</span><br>&#125;)<br><br>res.write(<span class="hljs-string">&#x27;数据&#x27;</span>);<br>res.end();<br></code></pre></div></td></tr></table></figure>

<h4 id="检测静态资源并响应"><a href="#检测静态资源并响应" class="headerlink" title="检测静态资源并响应"></a>检测静态资源并响应</h4><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-keyword">if</span> (currentUrl.indexOf(<span class="hljs-string">&#x27;/public&#x27;</span>) === <span class="hljs-number">0</span>) &#123;<br>    <span class="hljs-comment">// 检测静态资源并响应（略难）</span><br>    fs.readFile(<span class="hljs-string">&#x27;./&#x27;</span> + currentUrl, <span class="hljs-string">&#x27;utf8&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, data</span>) </span>&#123;<br>        <span class="hljs-keyword">if</span> (err) res.end(<span class="hljs-string">&#x27;404 Not Found&#x27;</span>);<br>        res.write(data);<br>        res.end();<br>    &#125;)<br>&#125;<br></code></pre></div></td></tr></table></figure>

<h3 id="六、表单提交数据处理（留言板案例）"><a href="#六、表单提交数据处理（留言板案例）" class="headerlink" title="六、表单提交数据处理（留言板案例）"></a>六、表单提交数据处理（留言板案例）</h3><figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 表单提交数据处理</span><br><span class="hljs-keyword">if</span> (req.method == <span class="hljs-string">&#x27;POST&#x27;</span>) &#123;<br>    <span class="hljs-comment">//明确：表单post提交的数据可能会非常大，所以分片获取</span><br>    <span class="hljs-comment">//说明：data事件-数据传输中，end事件-数据传输完毕</span><br>    <span class="hljs-keyword">var</span> postData = <span class="hljs-string">&#x27;&#x27;</span>;<br>    req.on(<span class="hljs-string">&#x27;data&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">chunk</span>) </span>&#123;<br>        postData += chunk; <br>    &#125;); <br>    req.on(<span class="hljs-string">&#x27;end&#x27;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-comment">//通过querystring模块将字符串数据转化为对象</span><br>        paramObj = querystring.parse(postData); <br>        <span class="hljs-comment">// 2. 入库（压入到数组中 push pop）</span><br>        <span class="hljs-keyword">var</span> d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();<br>        <span class="hljs-keyword">var</span> date = d.getFullYear() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getMonth() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getDate() + <span class="hljs-string">&#x27; &#x27;</span> + d.getHours() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getMinutes() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getSeconds();<br>        <span class="hljs-keyword">var</span> msg = &#123;<span class="hljs-attr">name</span>: paramObj.name, <span class="hljs-attr">content</span>: paramObj.content, <span class="hljs-attr">create_at</span>: date&#125;<br>        msgs.push(msg)<br>        <span class="hljs-comment">// 3. 跳转</span><br>        res.statusCode = <span class="hljs-number">302</span>;<br>        res.setHeader(<span class="hljs-string">&#x27;Location&#x27;</span>, <span class="hljs-string">&#x27;/&#x27;</span>);<br>        res.end()<br>    &#125;);<br>&#125; <span class="hljs-keyword">else</span> &#123;<br>    <span class="hljs-comment">// 1. 接收数据</span><br>    <span class="hljs-keyword">var</span> paramObj = url.parse(req.url, <span class="hljs-literal">true</span>).query<br>    <span class="hljs-comment">// 2. 入库（压入到数组中 push pop）</span><br>    <span class="hljs-keyword">var</span> d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();<br>    <span class="hljs-keyword">var</span> date = d.getFullYear() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getMonth() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getDate() + <span class="hljs-string">&#x27; &#x27;</span> + d.getHours() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getMinutes() + <span class="hljs-string">&#x27;-&#x27;</span> + d.getSeconds();<br>    <span class="hljs-keyword">var</span> msg = &#123;<span class="hljs-attr">name</span>: paramObj.name, <span class="hljs-attr">content</span>: paramObj.content, <span class="hljs-attr">create_at</span>: date&#125;<br>    msgs.push(msg)<br>    <span class="hljs-comment">// 3. 跳转</span><br>    res.statusCode = <span class="hljs-number">302</span>;<br>    res.setHeader(<span class="hljs-string">&#x27;Location&#x27;</span>, <span class="hljs-string">&#x27;/&#x27;</span>);<br>    res.end()<br>&#125;<br></code></pre></div></td></tr></table></figure>

<h3 id="⭐扩展"><a href="#⭐扩展" class="headerlink" title="⭐扩展"></a>⭐扩展</h3><h4 id="1-自定义网站图标"><a href="#1-自定义网站图标" class="headerlink" title="1. 自定义网站图标"></a>1. 自定义网站图标</h4><h4 id="2-MIME"><a href="#2-MIME" class="headerlink" title="2. MIME"></a>2. MIME</h4><p>MIME(Multipurpose Internet Mail Extensions) 是描述消息内容类型的英特网标准。</p>
<p>text/html - html文件    text/javascript - javascript文件   image/png - png文件</p>
<h4 id="3-状态码-301-amp-302"><a href="#3-状态码-301-amp-302" class="headerlink" title="3. 状态码 301 &amp; 302"></a>3. 状态码 301 &amp; 302</h4>
            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E5%89%8D%E7%AB%AF/">前端</a>
                    
                      <a class="hover-with-bg" href="/tags/nodejs/">nodejs</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均为本人原创，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/07/29/npm%E7%AC%94%E8%AE%B0/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">npm笔记</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/07/29/Express%E7%AC%94%E8%AE%B0/">
                        <span class="hidden-mobile">Express笔记</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->

  <div class="col-lg-7 mx-auto nopadding-x-md">
    <div class="container custom post-custom mx-auto">
      <img src="/img/agoni.gif" srcset="/img/loading2.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <h5 style="text-align: center; margin-top: 1rem;">谢谢您的光临噢！！！</h5> 
    </div>
  </div>


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <span>张宝文</span> <i class="iconfont icon-love"></i> <span>郑佳丽</span>  
	<!--《添加网站运行时间 -->
<br/>

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date(); 

function createtime() {
    //此处修改你的建站时间或者网站上线时间
    var grt = new Date('07/28/2021 19:00:00');
    now.setTime(now.getTime() + 250);
    days = (now - grt) / 1000 / 60 / 60 / 24;

    dnum = Math.floor(days);
    hours = (now - grt) / 1000 / 60 / 60 - (24 * dnum);
    hnum = Math.floor(hours);
    if (String(hnum).length == 1) {
        hnum = "0" + hnum;
    }
    minutes = (now - grt) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes);
    if (String(mnum).length == 1) {
        mnum = "0" + mnum;
    }
    seconds = (now - grt) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds);
    if (String(snum).length == 1) {
        snum = "0" + snum;
    }
    document.getElementById("timeDate").innerHTML = " 本站已各种夹缝中安全运行 " + dnum + " 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()", 250);
</script>

<!-- 添加网站运行时间》-->
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.3/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.1/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>



  <script  src="/js/local-search.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.js" ></script>
  <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>

  <script>
    function typing(id, title){
        var typed = new Typed('#' + id, {
            strings: [
              '  ',
              title + "&nbsp;",
            ],
            cursorChar: "❤",
            typeSpeed: 150,
            loop: false,
        });
        typed.stop();
        $(document).ready(function () {
            $(".typed-cursor").addClass("h2");
            typed.start();
        });
    }

    
        typing("subtitle", document.getElementById('subtitle').title)
    

  </script>













  
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/yinghua.js"></script>



<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>

</body>
</html>
